<?php
namespace Album\Controller;
use Think\Controller;

/**
 * Class AdminAlbumController
 * @package Album\Controller
 * 后台相册列表
 */
class AdminAlbumController extends Controller {
    private $model_name = 'Album';

    public function index(){
        $this->display();
    }

    public function getAll(){
        $list = D($this->model_name);
        $list = $list->getAll();
        echo json_encode($list);
    }

    public function add(){
        $model = D($this->model_name);
        if(IS_POST){
            $data = filterInput($_POST);
            $model->addObj($data);
            $this->success(LANG('save_success'));
        }else if(IS_GET){
            $this->display();
        }
    }

    public function edit(){
        $model = D($this->model_name);
        if(IS_POST){
            $data = filterInput($_POST);
            $model->save($data);
            $this->success(LANG('save_success'));
        }else if(IS_GET){
            $data = filterInput($_GET);
            $id = $data['id'];
            $obj = $model->queryObj($id, 'id');
            $this->assign('obj', $obj);
            $this->display();
        }
    }

    public function del(){
        $model = D($this->model_name);
        $data = filterInput($_GET);
        $id = $data['id'];
        $model->delete($id);
    }
}